import React,{Component} from 'react';
// import Header from '../component/header'
import api from '../api/index'
import URL from 'url'
// import ReactDOM from 'react-dom';
import '../assets/css/base.css'
import '../assets/css/index.css'

class Download extends Component {
    constructor(props) {
        super(props);
        this.state = {
            downloadList: [],
            env: 0,
            extra:''
        };
    }
    componentDidMount() {
        // 获取页面参数
        let params = URL.parse(window.location.href, true).query
        console.log(params)
        this.setState({env: Number(params.env)})
        this.getDownloadList(params.id)
    }
    getDownloadList(accessId) {
        console.log(accessId)
        api.download({accessId}).then(res =>{
            console.log(res)
            const downloadList = res.data;
            const extra = res.extra
            this.setState({ downloadList });
            this.setState({ extra });
            console.log(this.state);
        })
        // axios.post('http://192.168.1.250:9093/property-app/api/v1/access/download',qs.stringify({accessId}))
        //     .then(res => {
        //         console.log(res)
        //         const downloadList = res.data.data;
        //         const extra = res.data.extra
        //         this.setState({ downloadList });
        //         this.setState({ extra });
        //         console.log(this.state);
        //     });
    }
  render() {
    return (
      <div className="App">
          {/*<Header env={this.state.env}/>*/}
          <div className="wrap">
              <section>
                <div className="group">
                    {this.state.downloadList.length > 0 ?
                        this.state.downloadList.map(log =>
                            <div className="group-item" key={log.id}>
                                <div className="item-desc flexbox">
                                    <div className="item-logo">
                                        <img src={require(`../assets/images/${this.state.extra ? this.state.extra : 'logo.png'}`)} alt={log.name}/>
                                    </div>
                                    <div>
                                        <p className="item-title">{log.name}</p>
                                        <p>更新日期:{log.uploadDate}</p>
                                        <p>版本号:{log.version}</p>
                                    </div>
                                </div>
                                <div className="item-action">
                                    {/*<div className="item-text">*/}
                                    {/*<p>地產綜合服務平台</p>*/}
                                    {/*</div>*/}
                                    <div className="btns flexbox">
                                        {/*<a href="./history.html" className="button empty" >版本記錄</a>*/}
                                        <a href={log.url} className="button" >下載</a>
                                    </div>
                                </div>
                            </div>
                        )
                        :<h1 className='list-null'>暫無安裝包</h1>
                    }
                  </div>
              </section>
          </div>
      </div>
    );
  }
}

export default Download
// ReactDOM.render(<History />, document.getElementById('root'));
